//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
//==
//==
//==
//==================================================================

#ifndef M5D_TNODE_H
#define M5D_TNODE_H

#include "m5d_keyframe.h"
#include "m5d_types.h"

#define M5D_BONE_NAME_MAXLEN			32
#define M5D_TNODE_FLG_HASSKINMATRIX		1
#define M5D_TNODE_FLG_HASBASEKEYS		2

#define M5D_TNODE_FLG_RESERVED1			256
#define M5D_TNODE_FLG_RESERVED2			512

//==================================================================
// optimizing order assuming that structures are potentially aligned to more than 4
struct m5d_tnode_c
{
	char				_name[M5D_BONE_NAME_MAXLEN];

	PMath::Matrix44			_bone_vert_m;
	m5d_poskey_t		_base_poskey;
	m5d_rotkey_t		_base_rotkey;

	u_int				_flags;
	int					_n_poskeys, _n_alloc_poskeys;
	int					_n_rotkeys, _n_alloc_rotkeys;
	int					_n_scakeys, _n_alloc_scakeys;
	m5d_poskey_t		*_poskeysp;
	m5d_rotkey_t		*_rotkeysp;
	m5d_scakey_t		*_scakeysp;

//	class Mesh			*_groupp;		///< Associated group pointer.
	int					_mesh_idx;		///< Associated group index (must match the pointer above).

//	m5d_tnode_c			*_parentp;		///< Parent pointer.
	int					_parent_idx;	///< Parent index, used for storage.

//	m5d_tnode_c			*_childp;		///< Child pointer.
	int					_child_idx;		///< Child index, used for storage.

//	m5d_tnode_c			*_nextp;		///< Sibling pointer.
	int					_next_idx;		///< Sibling index, used for storage.

public:
	//==================================================================
	PError				m4tn_init( char *namep = 0, u_int flags = 0 );
	void				m4tn_name_set( char *namep );
	void				m4tn_flags_set( u_int flags );
	void				m4tn_free();

	m5d_rotkey_t		*m4tn_rotkeys_addn( int add_n );
	m5d_poskey_t		*m4tn_poskeys_addn( int add_n );
	m5d_scakey_t		*m4tn_scakeys_addn( int add_n );
	//--------------------------------------------------------------
};

#endif
